﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.sprite.changeSourceSize;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.util.resourceMan;
using Microsoft.Xna.Framework;
using imaginecup.util;

namespace Imaginecup.sprite
{
    public class RelativeSprite : ISprite
    {
        private String m_TextureName;
        private IRelativeSourceInfoClass m_RelativeInfo;

        public void SetTextureName(String name)
        {
            m_TextureName = name;
        }


        public void SetRelativeInfo(IRelativeSourceInfoClass relativeClass)
        {
            m_RelativeInfo = relativeClass;
        }


        public void Draw(SpriteBatch spriteBatch, EntityInfo entityInfo)
        {
            Texture2D texture = ResourceMan.GetResourceMan().GetTexture(m_TextureName);
            EntityInfo sourceInfo = m_RelativeInfo.GetRelativeSource();
            Vector2 offsetPos = m_RelativeInfo.GetOffsetPos();
            Vector2 offsetSize = m_RelativeInfo.GetOffsetSize();

            spriteBatch.Begin();
            spriteBatch.Draw(texture, new Rectangle((int)(entityInfo.mPosition.X + offsetPos.X), (int)(entityInfo.mPosition.Y + offsetPos.Y),
                                                     (int)(entityInfo.mSize.X + offsetSize.X), (int)(entityInfo.mSize.Y + offsetSize.Y))

                                    , new Rectangle((int)sourceInfo.mPosition.X, (int)sourceInfo.mPosition.Y,
                                                     (int)sourceInfo.mSize.X, (int)sourceInfo.mSize.Y)
                                    , Color.White);
            spriteBatch.End();
        }

        public void Release()
        {

        }
    }
}
